package com.demo.eshop.pdetail.request;

/**
 * @author: e20160504
 * @date: 2018/10/29
 * @desc
 */

import com.demo.eshop.pdetail.thread.RequestProcesserThreadPool;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ConcurrentHashMap;

/**
*@params:
*@return:
*@desc:  请求的内存队列
*/
public class RequestQueue {

    //内存队列
    private List<ArrayBlockingQueue<Request>> queues = new ArrayList<>();

    // 标志位
    private Map<Integer,Boolean> flag = new ConcurrentHashMap<>();

    /**
     * @params:
     * @return:
     * @desc: 单例：此处取用绝对线程安全的方式实现。静态内部类
     */
    public static class SingleTon {

        private static RequestQueue instance;

        static {
            instance = new RequestQueue();
        }

        private static RequestQueue getInstance(){
            return instance;
        }
    }

    public static RequestQueue getInstance(){
        return RequestQueue.SingleTon.getInstance();
    }

    public void addQueue(ArrayBlockingQueue<Request> queue){
        this.queues.add(queue);
    }

    public int queueSize(){
        return queues.size();
    }

    public ArrayBlockingQueue<Request> getQueue(Integer index){
        return queues.get(index);
    }

    public Map<Integer,Boolean> getFlagMap(){
        return flag;
    }
}
